<?php

if (!defined('BASEPATH'))
	exit('No direct script access allowed');

/**
 * Created by JetBrains PhpStorm.
 * User: b4by
 * Date: 1/23/13
 * Time: 10:17 AM
 * To change this template use File | Settings | File Templates.
 */
class ViewCatalogue extends MY_Controller {

	function __construct() {
		parent::__construct();
		$this->load->model('model_product');
	}

	public function index($cat_id) {

		$this->data['catalogue'] = $this->model_catalogue->get_info($cat_id);

		$products = $this->model_product->get_list($this->user_lang->id, array(
			'where' => array('end >=' => now()),
			'order' => array('p.id', 'desc')
				), $this->location, $cat_id);

		foreach ($products as &$product) {
			$product->thumb = image_url($product->thumb);
			$product->save = (int) (($product->price - $product->sale_price) * 100 / $product->price);
			$product->price = currency_format($product->price);
			$product->sale_price = currency_format($product->sale_price);
		}

		$this->data['products'] = $products;
		$this->data['temp'] = 'catalogue/index';
		$this->load_view();
	}

	public function _best_buys($cat_id) {
		$this->load->model('model_product');
		$this->load->helper('date');
		
		return $this->model_product->get_list($this->user_lang->id, array(
			'where' => array('end >=' => now()),
			'order' => array('total_orders', 'desc'),
			'limit' => array(0, $this->siteConfig->best_buys_num)
		), $this->location, $cat_id);
	}

}